<template>
  <div class="shopping-cart">
    <h2>购物车</h2>
    <ul>
      <li v-for="(item, index) in cartItems" :key="index">
        {{ item.name }} - ¥{{ item.price }} - 数量：{{ item.quantity }}
        <button @click="increment(index)">+</button>
        <button @click="decrement(index)">-</button>
      </li>
    </ul>
    <p>总价：¥{{ cartTotal }}</p>
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions } from 'vuex';

export default {
  computed: {
    ...mapState(['cartItems']),
    ...mapGetters(['cartTotal'])
  },
  methods: {
    ...mapActions(['increment', 'decrement'])
  }
};
</script>

<style scoped>
.shopping-cart {
  text-align: center;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  margin: 10px 0;
}
button {
  margin-left: 10px;
}
</style>